<?php namespace Home\Controller;
use Hdphp\Controller\Controller;
class ShopcarController extends Controller{
	public function index(){
		
		if(IS_POST){
			p(Q('post.'));
			$gid=Q('post.gid');
//			p($gid);
			$listtu=Db::table('Goods')->where("gid={$gid}")->pluck('listtu');
//			p($listtu);
			$data = array(
				'id'    	=> Q('post.gid',0,'intval'),
				'name'  	=> Q('post.gname',''),
				'num'	 	=> Q('post.gnum',0,'intval'),				
				'price' 	=> Q('post.gshang',0,'intval'),
				'options'   =>array(
								
								'color'	  => Q('post.颜色',''),
								'size'    => Q('post.尺码',''),
								'listview'=> $listtu,
							 ),
				
			);
			//用框架里的购物车类把新数组存入session里面
//			p($data);
//			die();
			Cart::add($data);
			p($_SESSION);
			die();
			//把购物车里需要的商品总数和商品总价组成一个数组，以JSON的形式返出去，页面中就可以接到
			$shop_info = array(
				'total_num'  =>$_SESSION['total_rows'],
				'total_price'=>$_SESSION['total'],
			);
			echo json_encode($shop_info);
			exit();
		}
//		session_unset();
//		session_destroy();
		if(isset($_SESSION['cart'])){
			$goods = $_SESSION['cart']['goods'];
		p($goods);
			View::with('goods',$goods);
		}
		
			
		

		
		View::make();
	}
	
	public function del(){
		$id=Q('get.kk');
//		p($id);die;
	unset($_SESSION['cart']['goods'][$id]);
	View::success('删除成功');
	}
}	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
?>